#pragma once
#include "protocol.hpp"

class NetCal
{
public:
    Responce Handler(Request &res)
    {
        Responce ret_res;
        int x = res.GetX();
        int y = res.GetY();
        char oper = res.GetOper();
        switch (oper)
        {
        case '+':
            ret_res.SetResult(x + y);
            ret_res.SetCode(0);
            break;
        case '-':
            ret_res.SetResult(x - y);
            ret_res.SetCode(0);
            break;
        case '*':
            ret_res.SetResult(x * y);
            ret_res.SetCode(0);
            break;
        case '/':
            if (y == 0)
            {
                ret_res.SetCode(1);
                break;
            }
            ret_res.SetResult(x / y);
            ret_res.SetCode(0);
            break;
        case '%':
            if (y == 0)
            {
                ret_res.SetCode(2);
                break;
            }
            ret_res.SetResult(x % y);
            ret_res.SetCode(0);
            break;
        default:
            ret_res.SetCode(3);
            break;
        }
        return ret_res;
    }
};